﻿/*
 * Created by SharpDevelop.
 * User: Corrado Mio
 * Date: 13/06/2012
 * Time: 21:37
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.Collections.Generic;
using System.Data.Common;

namespace CSharpExt.Data
{
    /// <summary>
    /// Description of DataResultRow.
    /// </summary>
    public class DataResultRow
    {
        #region Private Data
        
        private DataResultSet _rset;
        
        private DbDataReader _reader;
        
        #endregion
        
        #region Constructor
        
        internal DataResultRow(DataResultSet rset)
        {
            _rset = rset;
            _reader = rset.InnerReader;
        }
        
        #endregion
        
        #region Properties
        
        /// <summary>
        /// Numero di colonne
        /// </summary>
        public int Count
        {
            get { return _reader.FieldCount; }
        }
        
        #endregion
        
        #region Operations
        
        // IsNull
        
        public bool IsNull(String name)
        {
            return IsNull(ordinalOf(name));
        }
        
        public bool IsNull(int ordinal)
        {
            return _reader.IsDBNull(ordinal);
        }
        
        // Bool
        
        public bool GetBoolean(String name)
        {
            return GetBoolean(ordinalOf(name));
        }
        
        public bool GetBoolean(int field)
        {
            return _reader.GetBoolean(field);
        }
        
        // Int
        
        public int GetInteger(String name)
        {
            return GetInteger(ordinalOf(name));
        }
        
        public int GetInteger(int field)
        {
            return _reader.GetInt32(field);
        }
        
        // Long
        
        public long GetLong(String name)
        {
            return GetLong(ordinalOf(name));
        }
        
        public long GetLong(int field)
        {
            return _reader.GetInt64(field);
        }
        
        // Double
        
        public double GetDouble(String name)
        {
            return GetDouble(ordinalOf(name));
        }
        
        public double GetDouble(int field)
        {
            return _reader.GetDouble(field);
        }

        // String
        
        public String GetString(String name)
        {
            return GetString(ordinalOf(name));
        }
        
        public String GetString(int field)
        {
            return _reader.GetString(field);
        }
        
        // DateTime
        
        public DateTime GetDateTime(String name)
        {
            return GetDateTime(ordinalOf(name));
        }
        
        public DateTime GetDateTime(int field)
        {
            return _reader.GetDateTime(field);
        }
        
        #endregion
        
        #region Implementation
        
        internal int ordinalOf(String name)
        {
            return _rset.ordinalOf(name);
        }
        
        #endregion
    }
}
